﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace QS
{
    class QCoordinateSystem
    {
        private VertexBuffer m_VertexBuffer;

        private BasicEffect m_Effect;

        public void Load(GraphicsDevice gd)
        {

            m_VertexBuffer = new VertexBuffer(gd, typeof(VertexPositionColor), 6, BufferUsage.WriteOnly);

            VertexPositionColor[] vertices = new VertexPositionColor[6];

            vertices[0] = new VertexPositionColor(new Vector3(-1000f, 0f, 0f), Color.Red);
            vertices[1] = new VertexPositionColor(new Vector3(1000f, 0f, 0f), Color.Red);

            vertices[2] = new VertexPositionColor(new Vector3(0, -1000f, 0f), Color.Blue);
            vertices[3] = new VertexPositionColor(new Vector3(0, 1000f, 0f), Color.Blue);

            vertices[4] = new VertexPositionColor(new Vector3(0, 0, -1000f), Color.Lime);
            vertices[5] = new VertexPositionColor(new Vector3(0, 0, 1000f), Color.Lime);

            m_VertexBuffer.SetData<VertexPositionColor>(vertices);

            m_Effect = new BasicEffect(gd);
        }

        public void Draw(GraphicsDevice gd, Matrix view, Matrix proj)
        {
            gd.SetVertexBuffer(m_VertexBuffer);

            m_Effect.World = Matrix.Identity;
            m_Effect.View = view;
            m_Effect.Projection = proj;
            m_Effect.VertexColorEnabled = true;

            foreach (EffectPass pass in m_Effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                gd.DrawPrimitives(PrimitiveType.LineList, 0, 6);
            }
        }
    }
}
